import json

from ronglian_sms_sdk import SmsSDK


class SmsUtil:
    __instance=None
    def __new__(cls, *args, **kwargs):
        if not cls.__instance:
            cls.__instance = super().__new__(cls, *args, **kwargs)
            cls.smsSdk = SmsSDK(accId='8a216da87dc23fe1017dc7e173460230', accToken='d892dad64155469fb0e2fffe1cafdff6',
                            appId='8a216da87dc23fe1017dc7e6b7dd023a')

        return cls.__instance

    def send_message(self,mobile='18130184240',tid='1',code='1234'):

        sendback=self.smsSdk.sendMessage(tid=tid,mobile=mobile,datas=(code,5))
        # 把返回值转为字典
        sendback=json.loads(sendback)
        if sendback.get("statusCode")=='000000':
            print("发送成功")
        else:
            print('发送失败')
